/* <pre>
 * Copyright (c) The Loose Coupling Team.
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 *      http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 *</pre>
 */

package org.lc.example.app.requestor;

import org.lc.eic.api.requestreply.sync.RequestDispatcher;
import org.lc.eic.api.requestreply.sync.Requestor;
import org.lc.eic.core.pipesandfilters.exception.ProcessingException;
import org.lc.example.app.common.EncryptStringRequest;
import org.lc.example.app.common.EncryptedStringReply;



/**
 *  TODO: Add type comment here!!
 *	@author <a href="mailto:p.lycke@googlemail.com">PaLy</a>
 *
 * 
 */
public class AppRequestor implements Requestor<EncryptStringRequest, EncryptedStringReply>{

	private int id;

	public AppRequestor(int id){
		this.id =id;
	}
	RequestDispatcher<EncryptStringRequest, EncryptedStringReply> requestDispatcher;
	
	public void setRequestDispatcher(
			RequestDispatcher<EncryptStringRequest, EncryptedStringReply> requestDispatcher) {
		
		this.requestDispatcher=requestDispatcher;
		
	}

	
	public void start() throws ProcessingException{
		
		for (int i = 0; i < 100; i++) {
			
			String str = "string to encrypt mess_id_"+i+" requestor_id_"+id;
			String strAfter = requestDispatcher.request(new EncryptStringRequest(str)).getEncryptedString();
			
			
			String strToCompare= new StringBuffer(strAfter).reverse().toString();
			
			if(!str.equals(strToCompare)){
				throw new ProcessingException("Not a correct encrypted string [strBefore="+str+", strAfter="+strAfter+"]");
			}
			
			
		
		}
	}
	

}
